package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.Listing;
import com.qf.service.SellService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * --- 机魂大悦 ---
 *
 * @author L
 * @date 2024/7/23
 * @desc
 */

@RestController
@RequestMapping("/sell")
public class SellController {
    @Autowired
    private SellService service;

    @GetMapping("/list")
    public R findAll(@RequestParam HashMap<String, String> map) {
        // 分页
        int pageNum = Integer.parseInt(map.get("pageNum"));
        int pageSize = Integer.parseInt(map.get("pageSize"));
        PageHelper.startPage(pageNum, pageSize);

        List<Listing> list = service.finAll(map);
        PageInfo<Listing> info = new PageInfo<>(list);

        return R.ok(info);
    }

    @GetMapping("/delById")
    public R delById(int id) {

        boolean delById = service.delById(id);
        return R.ok(delById);
    }

    @PostMapping("/upData")
    public R upData(@RequestBody HashMap<String, String> map) {

        boolean ok = service.upDataMeasure(map);
        return R.ok(ok);
    }

    @GetMapping("/delMore")
    public R delMore(@RequestParam  List<Integer> ids) {
        boolean delMore = service.delMore(ids);
        return R.ok(delMore);
    }
    @PostMapping("/addFind")
    public R addFind(@RequestBody HashMap<String, String> map) {

        boolean ok = service.addFind(map);
        return R.ok(ok);
    }
}
